package Day05;

import  java.util.Arrays;

public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr = new int[6];

        arr[0] = 100;
        System.out.println(arr[0]+" "+arr[1]);
        arr[arr.length-1] = 1000;
        System.out.println(arr[5]);
        System.out.println();

        //遍历/迭代
        for(int i=0;i< arr.length;i++){
            //arr[i]=(i+1)*100;
            arr[i]=(int) (Math.random()*100);
            //if(arr[i]%3==0)
            System.out.println(arr[i]);
        }
        System.out.println();

        //扩容
        int[] arr1=Arrays.copyOf(arr,arr.length+3);
        for (int i=0;i< arr1.length;i++){
            System.out.println(arr1[i]);
        }
        System.out.println();


        //缩容
        int[] arr2=Arrays.copyOf(arr,arr.length-3);
        for (int i=0;i< arr2.length;i++){
            System.out.println(arr2[i]);
        }

        System.out.println(Arrays.toString(arr2));

    }
}
